<template>
  <div>
    <el-container style="flex-wrap: wrap;">
      <!-- 头部导航栏 -->
      <BreadHeader></BreadHeader>
      <XPannel>
        <template v-slot:header>
          <span>库存分析</span>
        </template>
        <template v-slot:default> </template>
      </XPannel>
    </el-container>
  </div>
</template>
    
    <script>
import http from "@/api/http";
import BreadHeader from "@/components/BreadHeader.vue";
import XPannel from "@/components/XPannel.vue";
import { mapState } from "vuex";

export default {
  components: {
    XPannel,
    BreadHeader
  },
  computed: {
    ...mapState(["name", "picture"]),
    userName() {
      return this.name;
    },
    userPicture() {
      return this.picture;
    },
  },
  methods: {
    // 跳转到修改信息页面
    to_xuigai() {
      this.$router
        .push("/backmanage/EditInfo")
        .then(() => {
          this.$message({
            type: "success",
            message: "已经到修改信息页面!",
          });
        })
        .catch((err) => {
          console.log(err);
          this.$message({
            type: "warning",
            message: "网页跳转失败!或您已在当前页面",
          });
        });
    },
    // 退出登录--方法
    logout() {
      this.$confirm("此操作将退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          const token = localStorage.getItem("token");
          // 假设http是一个已经配置好的axios实例
          http
            .get("/user/logout", {
              headers: {
                Authorization: token,
              },
            })
            .then((res) => {
              console.log(res);
              const token = res.token;
              localStorage.setItem("token", token);
              localStorage.setItem("token_is_exp", 1);

              // localStorage.clear();
              this.$router
                .push("/login")
                .then(() => {
                  this.$message({
                    type: "success",
                    message: "已经安全退出!",
                  });
                })
                .catch((err) => {
                  console.log(err);
                  this.$message({
                    type: "success",
                    message: "已经安全退出!网页跳转失败",
                  });
                });
            })
            .catch((error) => {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消退出",
          });
        });
    },
  },
};
</script>
    
<style>
</style>